/*public class Test {
    public static void main(String[] args) {
        int[] array1 = { 1, 2, 3, 4 };
        int[] array2 = new int[10];
        int[] array3 = new int[]{1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
        System.out.println(array1);
        System.out.println(array2);
        System.out.println(array3);
        int[] array4;
        array4 = new int[10];
        int[] array5;
        array5 = new int[]{1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
        char[] array6 = new char[10];
        double[] array7 = new double[10];
        boolean[] array8 = new boolean[10];
        String[] string = new String[10];
    }
}*/







/*
//数组的使用

public class Test {
    public static void main(String[] args) {
        int[] array = { 1, 2, 3, 4, 5};
        System.out.println(array[0]);
        System.out.println(array[1]);
        System.out.println(array[2]);
        System.out.println(array[3]);
        System.out.println(array.length);
    }
}*/







/*
//数组的遍历

public class Test {
    public static void main(String[] args) {
        int[] array = {1, 3, 5, 6};
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();

        //foreach 循环。左侧是接收数据的，右侧是数组名
        for (int x:
             array) {
            System.out.print(x + " ");
        }
        System.out.println();
    }
}*/







/*
//使用函数求最大值

import java.util.Scanner;

public class Test {

    public static int max2(int x,int y){
        return x > y ? x : y ;
    }

    public static int max3 (int x,int y ,int z){
        int max = max2(x,y);
        return max2(max,z);
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int y = scan.nextInt();
        int z = scan.nextInt();
        System.out.println(max2(x, y));
        System.out.println(max3(x , y , z ));
    }
}*/







/*
//数组的引用

public class Test {
    public static void func(){
        int[] array1 = new int[3];
        array1[0] = 10;
        array1[1] = 20;
        array1[2] = 30;
        for (int x:
                array1) {
            System.out.print(x + " ");
        }
        System.out.println();

        int[] array2 = new int[]{1 , 2 , 3 , 4 , 5 };
        array2[0] = 100;
        array2[1] = 200;
        for (int x:
             array2) {
            System.out.print(x + " ");
        }
        System.out.println();

        array1 = array2;
        array1[2] = 300;
        array1[3] = 400;
        array1[4] = 500;
        for (int x:
                array1) {
            System.out.print(x + " ");
        }
        System.out.println();
        for (int x:
                array2) {
            System.out.print(x + " ");
        }
        System.out.println();

        int[] array3 = null;//array3这个引用不指向任何对象
        System.out.println(array3.length);//空指针异常
    }

    public static void main(String[] args) {
        func();
    }
}*/







/*
//保存数据

public class Test {
    public static void main(String[] args) {
        int[] array = { 1 , 2 , 3 , 4 };
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
    }
}*/







/*
//作为函数的参数

public class Test {
    public static void func1(int[] array){
    array = new int[10];//改变了形参的指向
}

    public static void func2(int[] array){
        array[0] = 99;
    }

    public static void main(String[] args) {
        int[] array1 = {1 , 2 ,3 ,4 };
        func1(array1);
        for (int i = 0; i < args.length; i++) {
            System.out.print(array1[i] + " ");//1 2 3 4
        }
        System.out.println();


        int[] array2 = {1 , 2 ,3 ,4 };
        func2(array2);
        for (int i = 0; i < array2.length; i++) {
            System.out.print(array2[i] + " ");
        }
        System.out.println();
    }
}
*/







/*
//数组作为返回值

public class Test {

    public static int[] func(){
        int[] array = {1 , 2 , 3 , 4 , 5 };
        return array;
    }

    public static void main(String[] args) {
        int[] ret = func();
        for (int i = 0; i < ret.length; i++) {
            System.out.print(ret[i] + " ");
        }
        System.out.println();
    }
}*/







/*
//数组作为返回值

import java.util.Arrays;

public class Test {
    public static int[] func(){
        return new int[]{1 , 2 , 3 , 4 , 5};
    }
    public static void main(String[] args) {
        int[] ret = func();
        String s = Arrays.toString(ret);
        System.out.println(s);
        System.out.println(Arrays.toString(ret));//借助工具类将参数的数组转化为字符串输出
    }
}*/







//写一个方法实现Arrays.toString

/*public class Test {
    public static String myToString(int[] array){
        String ret = "[";
        for (int i = 0; i < array.length; i++) {
            ret += array[i];
            if(i != array.length -1){
                ret += ", ";
            }
        }
        ret += "]";
        return  ret;
    }
    public static void main(String[] args) {
        int[] array = {1 , 2 , 3 , 4 , 5 , 6 };
        String ret = myToString(array);
        System.out.println(ret);
    }
}*/







/*//数组的拷贝

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int[] array = { 1 , 2 , 3 , 4 , 5 };
        int[] copy = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            copy[i] = array[i];
        }
        System.out.println(Arrays.toString(copy));
    }
}*/







/*//数组的拷贝

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int[] array = {1 , 2 , 3 , 4 , 5 };
        int[] ret = Arrays.copyOf(array, array.length);
        System.out.println(Arrays.toString(ret));
    }
}*/







/*//数组扩容

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int[] array = {1 , 2 , 3 , 4 , 5 };
        int[] ret = Arrays.copyOf(array, array.length * 2);
        System.out.println(Arrays.toString(ret));
    }
}*/








/*
//指定范围拷贝数组

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int[] array = { 1, 2, 3, 4, 5};
        int[] copy = Arrays.copyOfRange(array,1,4);//2 3 4
        System.out.println(Arrays.toString(copy));
    }
}*/







/*
//数组的拷贝

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int[] array = { 1, 2 , 3, 4, 5};
        int[] copy = new int[array.length];
        System.arraycopy(array,0, copy , 0 , array.length);
        System.out.println(Arrays.toString(copy));
    }
}
*/







//求数组中元素的平均值

/*public class Test {

    public static double avg(int[] array){
        int sum = 0;
        for (int x:array){
            sum += x;
        }
        return (double) sum / (double) array.length;
    }
    public static void main(String[] args) {
        int[] array = { 1, 2, 3, 4, 5 ,6};
        System.out.println(avg(array));
    }
}*/







/*
//查找数组中的某个元素

public class Test {
    public static int findVal(int[] array,int k){
        for (int i = 0; i < array.length; i++) {
            if(array[i] == k){
                return i;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int[] array = { 1, 2, 3, 4, 5};
        int k = 2;
        */
/*int ret = findVal(array,k);
        System.out.println(ret);*//*

        System.out.println(findVal(array, k));
    }
}*/








/*//二分查找数组中的某个元素

import java.util.Arrays;

public class Test {

    public static int binarySearch(int[] array,int k){
        int left = 0;
        int right = array.length - 1;
        while(left <= right){
            int mid = (left + right) / 2;
            if(mid < k){
                left = mid + 1;
            }else if (mid > k){
                right = mid - 1;
            }else {
                return mid;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int[] array = {1 ,2 ,13 ,54 ,25 ,4 ,81};
        int k = 20;
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
        System.out.println(binarySearch(array, k));
    }
}*/







/*
//二分查找数组中的某个元素

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int[] array = {1 ,2 ,13 ,54 ,25 ,4 ,81};
        int k = 14;
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
        System.out.println(Arrays.binarySearch(array, k));
    }
}*/
